package com.mz.ozy.mvp.presenter;

import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.MeBean;
import com.mz.ozy.bean.MyIntegralBean;
import com.mz.ozy.mvp.model.MyIntegralModel;
import com.mz.ozy.mvp.view.MyIntegralContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;


public class MyIntegralPresenter extends BasePresenterImpl<MyIntegralContract.View> implements MyIntegralContract.Presenter {

    private MyIntegralModel mModel;

    public MyIntegralPresenter() {
        mModel = new MyIntegralModel();
    }

    @Override
    public void getMeInfo(Activity activity, boolean isShow) {
        mModel.getMeInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MeBean>(mView, isShow) {
                    @Override
                    public void onSuccesss(MeBean bean) {
                        mView.getgetMeInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void onSign(Context context) {
        mModel.onSign(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onSignSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onMakeUp(Context context, String datetime) {
        mModel.onMakeUp(context, datetime)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onMakeUpSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onInfo(Context context) {
        mModel.onInfo(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MyIntegralBean>(mView, false) {
                    @Override
                    public void onSuccesss(MyIntegralBean bean) {
                        mView.onInfoSuccess(bean);
                    }
                });
    }
}
